﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TWiStEr.Math;

namespace TWiStEr.OpenGL.Utilities {
	public partial class Camera {
		public Vector Position;
		public Vector View;
		public Vector Up;
		protected double fov = DefaultFOV;
		public double FOV {
			get { return fov; }
			set {
				if (fov < 0 || 360 <= fov) throw new ArgumentOutOfRangeException("value", "FOV must be in range: [0, 360]");
				fov = value;
			}
		}
		private static Vector DefaultPos = new Vector(0, 0, 0);
		private static Vector DefaultView = new Vector(0, 0, 0);
		private static Vector DefaultUp = new Vector(0, 1, 0);
		private static double DefaultFOV = 60;
		public bool CaptureMouse { get; set; }
		protected Vector? AlwaysLookAtCenter { get; set; }
		public Vector AlwaysLookAt {
			set {
				AlwaysLookAtCenter = value;
				IsChanged = true;
			}
			get {
				return AlwaysLookAtCenter.Value;
			}
		}
		public bool IsLockedAtCenterPosition {
			get { return AlwaysLookAtCenter != null; }
			set {
				if (value) throw new InvalidOperationException("Use AlwaysLookAt to lock on a position");
				AlwaysLookAtCenter = null;
			}
		}

		protected bool IsChanged { get; set; }

		double aspect;
		int windowWidth;
		int windowHeight;

		public override string ToString() {
			return string.Format("Camera({0}, {1}, {2})\r\nWindow: {3}x{4}", Position, View, Up, windowWidth, windowHeight);
		}

	}
}
